﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using TTBusiness.DB_Linq;


namespace TTController
{
    public class clsBusiness
    {
        TTMarketing_DBDataContext objDB = new TTMarketing_DBDataContext();
        public List<tblProduct> Product_getAllTypeProduct(bool visible, bool status)
        {
            try
            {
                var l = from a in objDB.tblProducts
                        where a.Visible.Equals(visible) && a.Status.Equals(status)
                        select a;
                return l.ToList<tblProduct>();


            }
            catch (Exception)
            {

                throw;
            }
        }

        public List<tblSupport> Support_GetAll()
        {
            try
            {
                var l = from s in objDB.tblSupports
                        select s;
                List<tblSupport> list = new List<tblSupport>();
                list = l.ToList<tblSupport>();
                foreach (var item in list)
                {
                    item.Nick = item.tblTypeSupport.Pattern.Replace(item.tblTypeSupport.Parameter, item.Nick);
                }
                return list;
            }
            catch (Exception)
            {

                throw;
            }
        }

        public List<tblNew> News_getByTop(int top, bool status)
        {
            try
            {
                var l = (from a in objDB.tblNews
                        where a.Status.Equals(status) && a.tblCateNew.TypeID.Equals(6)
                        select a).Take(top);
                return l.ToList<tblNew>();


            }
            catch (Exception)
            {

                throw;
            }
        }

        public List<tblProduct> Product_searchByName(string proName, bool status)
        {
            try
            {
                var l = from a in objDB.tblProducts
                         where a.Status.Equals(status) && a.Name.Contains(proName)
                         select a;
                return l.ToList<tblProduct>();


            }
            catch (Exception)
            {

                throw;
            }
        }
    }
}
